package GUI;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import Client.Client;

public class EditFrame extends JFrame implements ActionListener {
	// Variabelbös
	JTextField doctorField, nurseField, patientField, commentField,
			patientIDField;
	String doctor, nurse, patient, comment, patientID;
	Client client;
	JButton editButton, exitButton;

	public EditFrame(Client client, String dataString) {
		super("Show journal");

		String[] temp;
		String delimiter = "#";
		temp = dataString.split(delimiter);

		doctor = temp[0];
		nurse = temp[1];
		comment = temp[2];
		patient = temp[3];
		patientID = temp[4];

		setVisible(true);
		this.setSize(500, 100);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.client = client;

		setLayout(new GridLayout(6, 2));

		// lägg till bös i listan;

		doctorField = new JTextField(doctor);
		add(new JLabel("Doctor"));
		add(doctorField);

		nurseField = new JTextField(nurse);
		add(new JLabel("Nurse:"));
		add(nurseField);

		patientField = new JTextField(patient);
		add(new JLabel("Patient:"));
		add(patientField);

		patientIDField = new JTextField(patientID);
		add(new JLabel("PatientID"));
		add(patientIDField);

		commentField = new JTextField(comment);
		add(new JLabel("Comment:"));
		add(commentField);

		exitButton = new JButton("Exit");
		add(exitButton);
		editButton = new JButton("Exit");
		add(editButton);

		pack();

		editButton.addActionListener(this);
		exitButton.addActionListener(this);

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		client.sendText("edit_j", doctor, nurse, comment, patientID);
		String answer = client.listen();
		if(!answer.equals("ok")){
			//här ska det vara ett error message
		}
		new JournalFrame(client);
		this.setVisible(false);
	}

	public void warningMessage(String s) {
		System.out.print(s);
	}
}
